<?php

/**
 * =====================================
 * Definición de rutas de la aplicación.
 * =====================================
 */
$app->param('uuid', '[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}');

// Autenticación.
$app->use('signup', [
    \App\Middlewares\AuthMiddleware::class.'@redirect',
    \App\Middlewares\CsrfMiddleware::class.'@protect',
]);
$app->get('signup', \App\Controllers\AuthController::class.'@signupView');

$app->use('signup/action', [
    \App\Middlewares\AuthMiddleware::class.'@redirect',
    \App\Middlewares\CsrfMiddleware::class.'@verify',
]);
$app->post('signup/action', \App\Controllers\AuthController::class.'@signupAction');

$app->use('login', [
    \App\Middlewares\AuthMiddleware::class.'@redirect',
    \App\Middlewares\CsrfMiddleware::class.'@protect',
]);
$app->get('login', \App\Controllers\AuthController::class.'@loginView');

$app->use('login/action', [
    \App\Middlewares\AuthMiddleware::class.'@redirect',
    \App\Middlewares\CsrfMiddleware::class.'@verify',
]);
$app->post('login/action', \App\Controllers\AuthController::class.'@loginAction');

$app->get('logout', \App\Controllers\AuthController::class.'@logout');

// Contactos.
$app->use('contacts', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
]);
$app->get('contacts', \App\Controllers\ContactController::class.'@index');

$app->use('contacts/new', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@protect',
]);
$app->get('contacts/new', \App\Controllers\ContactController::class.'@new');

$app->use('contacts/create', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@verify',
]);
$app->post('contacts/create', \App\Controllers\ContactController::class.'@create');

$app->use('contacts/:uuid', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
]);
$app->get('contacts/:uuid', \App\Controllers\ContactController::class.'@show');

$app->use('contacts/edit/:uuid', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@protect',
]);
$app->get('contacts/edit/:uuid', \App\Controllers\ContactController::class.'@edit');

$app->use('contacts/update/:uuid', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@verify',
]);
$app->post('contacts/update/:uuid', \App\Controllers\ContactController::class.'@update');

$app->use('contacts/remove/:uuid', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@protect',
]);
$app->get('contacts/remove/:uuid', \App\Controllers\ContactController::class.'@remove');

$app->use('contacts/delete/:uuid', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@verify',
]);
$app->post('contacts/delete/:uuid', \App\Controllers\ContactController::class.'@delete');

// Perfil.
$app->use('profile', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@protect',
]);
$app->get('profile', \App\Controllers\ProfileController::class.'@edit');

$app->use('profile/update', [
    \App\Middlewares\AuthMiddleware::class.'@check',
    \App\Middlewares\RoleMiddleware::class.'@check',
    \App\Middlewares\CsrfMiddleware::class.'@verify',
]);
$app->post('profile/update', \App\Controllers\ProfileController::class.'@update');
